<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="com.appspot.yozmcup.DO.User" %>
<%@ page import="com.google.appengine.api.datastore.DatastoreService" %>
<%@ page import="com.google.appengine.api.datastore.DatastoreServiceFactory" %>
<%@ page import="com.google.appengine.api.datastore.FetchOptions" %>
<%@ page import="com.google.appengine.api.datastore.PreparedQuery" %>
<%@ page import="com.google.appengine.api.datastore.Query" %>
<%
	User user = (User) session.getAttribute("user");
%>
<!doctype html>
<html>
<head>
	<meta http-equiv="content-type" content="text/html; charset=UTF-8">
	<title>YOZMCUP</title>
	<script type="text/javascript" src="/js/jigu.min.js"></script>
	<link type="text/css" rel="stylesheet" href="/css/common.css" />
</head>
<body>
<p>
	<a class="title" href="http://yozmcup.appspot.com/">yozmCup</a>&nbsp;&nbsp;
<%
	if(user != null){
%>
	<a class="etc_link" href="/Logout">Logout</a>
	<br /><br />
	<a class="title" href="http://yozm.daum.net/<%= user.getUrlName() %>" target="_blank"><%= user.getNickname() %></a> 님 접속중... 
	
<%
	}
%>
</p>
<%
	if(user == null || user.getUrlName() == null){
%>
	<br /><br />
		인증되지 않았습니다.
<%
	}else{
		DatastoreService dataStore = DatastoreServiceFactory.getDatastoreService();
		Query q = new Query("Winner");
		PreparedQuery pq = dataStore.prepare(q);
		int cnt = pq.countEntities(FetchOptions.Builder.withLimit(10));
		String disable = "";
		String disableReason = "";
		if(cnt < 8){
			disable = "disabled=\"disabled\"";
			disableReason = "(요즘컵 우승자가 부족합니다)";
		}
%>
<div id="stage" class="common_box r1 shadow1">
	<p id="gameRound"></p>
	<div id="fisrtMember" class="member_stage"></div><span class="member_vs">VS</span><div id="secondMember" class="member_stage"></div>
	<div class="cl">&nbsp;</div>
</div>
<div id="result" class="common_box r1 shadow1"></div>
<input type="button" title="요즘컵 참여!" value="" id="startCup" title="start yozmcup" />
<div id="selector">
	<h5>참가자 선택</h5>
	<input type="radio" id="normal" value="normal" name="kind" checked="checked" /> <label for="normal" class="rd">요즘 친구</label>&nbsp;&nbsp;
	<input type="radio" id="winner" value="winner" name="kind" <%= disable %>/> <label for="winner" class="rd">요즘컵 우승자<%= disableReason %></label>
</div>
<form id="writeForm" name="writeForm" method="post" action="/YozmWrite" onSubmit="doWrite(); return false;">
	<input type="hidden" id="message" name="message" />
	<input type="hidden" id="img_url" name="img_url" />
	<input type="button" value="요즘에 글쓰기" id="write" />
</form>
<p id="loadInfo">요즘컵 아이콘을 누르면 게임이 시작됩니다.</p>
<script type="text/javascript" src="/js/game.js"></script>
<% } %>
</body>
</html>